# -*- coding: utf-8 -*-
#!/usr/bin/python

##copyright 2014 Sebastian Stetter
##This file is part of the Lemonade Small Business Suite project and released under GPL v2
##http://lemonade.sebastianstetter.de
from camelot.view.art import Icon
from camelot.admin.application_admin import ApplicationAdmin
from camelot.admin.section import Section
from camelot.admin.action import application_action, form_action,  list_action
from camelot.core.utils import ugettext_lazy as _
from lemonade.model import *
from camelot.model.authentication import AuthenticationMechanism

from PyQt4.QtGui import QIcon,  QPixmap

class MyApplicationAdmin(ApplicationAdmin):
  
    name = 'Lemonade : : Small Business Suite'
    application_url = 'http://lemonade.sebastianstetter.de'
    help_url = 'http://lemonade.sebastianstetter.de/docs'
    author = 'Sebastian Stetter'
    domain = 'lemonade.sebastianstetter.de'
    version="0.0.1 - dev"
    database_selection=False
    
    def get_splashscreen(self):
        """:return: a :class:`PyQt4.QtGui.QPixmap` to be used as splash screen"""
        qpm = QPixmap('splash.png')
        img = qpm.toImage()
        # support transparency
        if not qpm.mask(): 
            if img.hasAlphaBuffer(): bm = img.createAlphaMask() 
            else: bm = img.createHeuristicMask() 
            qpm.setMask(bm) 
        return qpm
        
    def get_stylesheet(self):
        from camelot.view import art
        #styles=['navpane_office2007_black.qss', 'black.qss', 'office2007_blue.qss', 'navpane_office2007_silver.qss', 'navpane3_office2007_silver.qss', 'navpane3_office2007_black.qss', 'office2007_black.qss', 'navpane_office2007_blue.qss', 'office2007_silver.qss', 'navpane3_office2007_blue.qss']
        return art.read('stylesheet/office2007_silver.qss')

    def get_icon(self):
        """:return: the :class:`camelot.view.art.Icon` that should be used for the application"""
        return QIcon('lemon-icon.png')
    
    def get_sections(self):
        from camelot.model.memento import Memento
        from camelot.model.i18n import Translation
        from camelot.model.i18n import Translation
        from lemonade.actions import OpenSettingsView

        return [ 
                Section(_('Customers'), 
                        self, 
                        Icon('tango/22x22/apps/system-users.png'),
                        items=[Customer, Opportunity,  Voucher, Document, TargetList, Tag]), 
                Section(_('Company'), 
                        self, 
                        Icon('tango/22x22/actions/go-home.png'),
                        items=[Product, PaymentTerm, TaxKey, ]), 
                Section(_('User Related'), 
                        self, 
                        Icon('tango/22x22/actions/go-home.png'),
                        items=[User, 
                               # PetOwner,S
                               #Pet
                               ]), 
                Section(_('Preferrrences'), 
                        self, 
                        Icon('tango/22x22/categories/applications-system.png'),
                        items=[ContactMechanismType, ProductType, DocumentType, NextStepAction, User, EmailAction, VoucherType, TaxKey, ShippingMethod, Currency, PaymentTerm, Unit,  OpenSettingsView()]), 
                Section( _('My classes [delevlopers only]'),
                          self,
                          Icon('tango/22x22/categories/applicatioons-development.png'),
                          items = [Customer, 
                                    Address,  
                                    ContactMechanism, 
                                    ContactMechanismType, 
                                    Category, 
                                    TargetList, 
                                    BusinessTransaction, 
                                    Voucher, 
                                    VoucherType, 
                                    PrintTemplate, 
                                    VoucherPosition, 
                                    PaymentTerm, 
                                    PaymentTermTranslation, 
                                    Product, 
                                    TaxKey, 
                                    TaxKeyTranslation,
                                    Unit, 
                                    UnitTranslation,
                                    Currency, 
                                    ShippingMethod, 
                                    ProductType, 
                                    Contact, 
                                    Document, 
                                    DocumentType, 
                                    Tag, 
                                    Opportunity, 
                                    NextStepAction, 
                                    SalesStage,
                                    Leadsource, 
                                    OppRejectionReason, 
                                    Industry, 
                                    EmailAction, 
                                    EmailTemplate, 
                                    Preferences, 
                                    User, 
                                    AuthenticationMechanism
                                    ] ),
                 Section( _('Configuration'),
                          self,
                          Icon('tango/22x22/categories/preferences-system.png'),
                          items = [Memento, Translation] ), 
                ]
    def get_about(self):
        """:return: the content of the About dialog, a string with html
                syntax"""
        import datetime
        from camelot.core import license
        today = datetime.date.today()
        return """<b>Lemonade : : Small Business Suite v%s</b><br/>
                   Billing, customer relationship and document management for small businesses.
                  <p>
                  Copyright &copy; 2013-%s Sebastian Stetter.
                  All rights reserved.
                  </p>
                  <p>
                  %s
                  </p>
                  <p>
                  http://lemonade.sebastianstetter.de<br/>
                  </p>
                  """%(self.version,  today.year, license.license_type)
                  

# begin actions
    def get_actions(self):
        from camelot.admin.action import OpenNewView
        
        new_customer_action = OpenNewView( self.get_related_admin(Customer) )
        new_customer_action.icon = Icon('tango/32x32/actions/contact-new.png')
        
        new_voucher_action = OpenNewView( self.get_related_admin(Voucher) )
        new_voucher_action.icon = Icon('tango/32x32/apps/accessories-calculator.png')
        
        new_contact_action = OpenNewView( self.get_related_admin(Contact) )
        new_contact_action.icon = Icon('tango/32x32/actions/mail-reply-all.png')
        
        new_document_action = OpenNewView( self.get_related_admin(Document) )
        new_document_action.icon = Icon('tango/32x32/actions/document-new.png')


        return [new_customer_action,  new_voucher_action, new_contact_action, new_document_action]
# end actions

    def get_form_toolbar_actions(self, toolbar_area):
        
        form_toolbar_actions = [ ValidateFormBeforeCloseFormAction(),  #replace form_action.CloseForm()
                        form_action.ToFirstForm(),
                         form_action.ToPreviousForm(),
                         form_action.ToNextForm(),
                         form_action.ToLastForm(),
                         #application_action.Refresh(),
                         form_action.ShowHistory() #insert any other desired form_toolbar_action here
                         ]
        
        return form_toolbar_actions         
